package ${package.Controller};


import ${package.Entity}.${entity};
import ${dtoPackage}.${entity}SaveDTO;
import ${dtoPackage}.${entity}QueryDTO;
import ${voPackage}.${entity}VO;
import ${package.Service}.${table.serviceName};
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jingyuan.framework.rest.RestResponse;
import java.util.Set;
import javax.validation.Valid;
import com.jingyuan.framework.i18n.I18nUtils;
import com.jingyuan.framework.function.parse.FunctionDataDefine;
import com.jingyuan.framework.function.parse.ResourceBindDefine;

/**
  * <p>
  * ${table.comment!}-- 相关接口
  * </p>
* @author ${author}
* @since ${date}
*/
@FunctionDataDefine(name = "${table.comment!}", uniqueCode = "${package}", parentUniqueCode = "${package}", parentName = "xx管理", isLefat = false)
@Api(value = "${table.comment!}", tags = "${table.comment!}")
@RestController
@RequestMapping("<#if package.ModuleName?? && package.ModuleName != "">/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
public class ${table.controllerName} {

    @Autowired
    private ${table.serviceName} ${table.serviceName?uncap_first};

    @FunctionDataDefine(name = "新增/修改")
    @ResourceBindDefine
    @PostMapping("/save")
    @ApiOperation(value="保存信息",notes="id=0为新增，id>0为修改")
    public RestResponse add(@RequestBody @Valid ${entity}SaveDTO ${entity?uncap_first}DTO) {
        ${table.serviceName?uncap_first}.save(${entity?uncap_first}DTO);
        return RestResponse.ok();
    }


    @FunctionDataDefine(name = "删除")
    @ResourceBindDefine
    @ApiOperation(value = "批量删除")
    @PostMapping("/dels")
    public RestResponse batchDel(@RequestBody Set<Integer> ids) {
        if (ids == null || ids.isEmpty()) {
            return RestResponse.fail(I18nUtils.getRequestText("params.miss"));
        }
        ${table.serviceName?uncap_first}.delete(ids);
        return RestResponse.ok();
    }


    @FunctionDataDefine(name = "查询")
    @ResourceBindDefine
    @PostMapping("/query")
    @ApiOperation("列表查询")
    public RestResponse<${entity}VO> query(@RequestBody ${entity}QueryDTO queryDTO) {
        return RestResponse.ok(${table.serviceName?uncap_first}.query(queryDTO));
    }

    @ResourceBindDefine(bindFunctionCodes = {"${table.controllerName}.query"})
    @ApiOperation(value = "查询详情")
    @GetMapping("/get/{id}")
    public RestResponse<${entity}VO> get(@PathVariable("id") int id) {
       return RestResponse.ok(${table.serviceName?uncap_first}.get(id));
    }

 }
